package com.mlink.ai.chat.ui.activity.chat

import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.mlink.ai.chat.assistant.robot.R

class ChatAdapter(var dataList: MutableList<ChatItemBean>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(viewType, parent,false)
        return when (viewType) {
            ITEM_TYPE_GUIDE,
            ITEM_TYPE_QUESTION,
            ITEM_TYPE_ERROR,
            ITEM_TYPE_ANSWER -> {
                ChatViewHolder(view)
            }
            else -> {
                LoadingViewHolder(view)
            }
        }


    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val bean = dataList[position]
        if(holder is ChatViewHolder){
            holder.textContent.text = bean.itemText
        }
        holder.itemView.setOnClickListener {
            if (bean.itemType == ITEM_TYPE_ANSWER) {
                Log.e("zzzz", "点击了答案: ")
            } else {
                Log.e("zzzz", "点击了问题: ")
            }
        }
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    override fun getItemViewType(position: Int): Int {
        return dataList[position].itemType
    }

    inner class ChatViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var textContent: TextView = itemView.findViewById(R.id.tv_msg_content)
    }
    inner class LoadingViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

    }


}